﻿using DataManageSystem.Common;
using DataManageSystem.Models;
using DataManageSystem.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace DataManageSystem.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class MailController : ControllerBase
    {
        private readonly IMailService _mailService;
        public MailController(IMailService mailService)
        {
            _mailService = mailService;
        }

        [HttpPost("send")]
        public async Task<ObjectResult> SendEmail([FromBody] MailRequest request)
        {
            try
            {
                await _mailService.SendEmailAsync(request);
                return new ObjectResult(Result.Success("邮件发送成功"));
            }
            catch
            {
                return new ObjectResult(Result.Error("邮件发送失败"));
            }
        }
    }
}
